// custom-tab-bar/index.js
Component({
  /**
   * 组件的初始数据
   */
  data: {
    selected: 0, // 当前选中的下标
    color: '#353535', // tabbar 未选中字体的颜色
    selectedColor: "#7DC9EA", // tabbar 选中字体的颜色
    list: [ // tababr 循环数据集
      {
        "pagePath": "/pages/index/index",
        "iconPath": "/images/home.png",
        "selectedIconPath": "/images/home-sel.png",
        "text": "首页"
      },
      {
        "pagePath": "/pages/statistical/statistical",
        "iconPath": "/images/article.png",
        "selectedIconPath": "/images/article-sel.png",
        "text": "科普"
      },
      {
        "pagePath": "/pages/add/add",
        "iconPath": "/images/ico-sign.png",
        "selectedIconPath": "/images/ico-sign.png",
        "text": "",
        "isSpecial": true
      },
      {
        "pagePath": "/pages/category/category",
        "iconPath": "/images/shop.png",
        "selectedIconPath": "/images/shop-sel.png",
        "text": "商城"
      },
      {
        "pagePath": "/pages/my/index",
        "iconPath": "/images/my.png",
        "selectedIconPath": "/images/my-sel.png",
        "text": "我的"
      }
    ]
  },
  attached() {},
  methods: {
    switchTab(e) {
      let data = e.currentTarget.dataset;
      console.log('切换的是', data);
      let url = data.path;
      console.log('url',url)
      // this.setData({
      //   selected: data.index
      // })
      // 跳转到 tabbar 页，关闭其他所有非 tabbar 页
      wx.switchTab({
        url
      });
      // this.init()
      console.log('最后选择idxx',this.data.selected)
    },
    init() {
      const page = getCurrentPages().pop();
      var selected = this.data.list.findIndex(item => item.pagePath === `/${page.route}`)
      console.log('pagjinde',selected)
      this.setData({
        selected
      });
      console.log('最后选择id',this.data.selected)
    }
  }
})